<?php

Raise::load('core.RaiseDataType');
Raise::load('core.IRaiseComparable');

/**
 * RaiseVersion class
 * storing and comparing version numbers / strings
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.Core.DataStructure
 * @since 1.2
 */
class RaiseVersion extends RaiseDataType implements IRaiseComparable {

    /**
     * Version string
     * @var string
     */
    private $version;

    /**
     * Creates a new version object
     * @param string $v
     */
    function __construct($v) {
        $this->version = $v;
    }

    /**
     * Returns the version in string
     * @return string
     */
    function __toString() {
        return $this->version;
    }

    /**
     * Compare another version with this version.
     * @param RaiseVersion|string $v The version to compare this version with.
     * @param string $op (Optional) The comparison operator to use
     * @return double|integer|boolean Comparison result
     * @link http://php.net/version-compare
     */
    public function compareTo($v, $op = null) {
        if($op === null){
            return version_compare($this->version, $v);
        }else{
            return version_compare($this->version, $v, $op);
        }
    }

}